package org.diy.traffic.sinks;

import java.util.Date;
import java.util.logging.Level;

import org.diy.traffic.twitter.TrafficTwitter;
import org.diy.traffic.util.TLog;

public abstract class TwitterSink extends TrafficSink {
	
	public static final String DM_RECIPIENT = "Direct Message Recipient";
	
	private long chillaxUntil = -1;
	
	protected TrafficTwitter myTwitter;
	
	protected final static int DEFAULT_RATE_LIMIT= 4;
	
	protected boolean inChillaxMode() {
		if (chillaxUntil >= 0) {
			if (chillaxExpired()) {
				TLog.log(Level.FINEST, "Chillax period has expired!");
				resetChillax();
				return false;
			} else {
				TLog.log(Level.FINER, "Waiting for chillax period to expire");
				return true;
			}
		} else 
			return false;
	}
	
	
	protected boolean chillaxExpired() {
		return (System.currentTimeMillis() >= chillaxUntil);
	}
	
	protected long getChillaxUntil() {
		return chillaxUntil;
	}
	
	protected void setChillaxUntil (long l) {
		chillaxUntil = l;
	}
	
	protected void resetChillax() {
		setChillaxUntil(-1);
	}
	
	public TwitterSink(String username, String password, int rateLimit) {
		super(username, rateLimit);
	
		myTwitter = new TrafficTwitter(username, password);
	}
}
